local zhizi = fk.CreateSkill{
    name = "lingling__zhizi",
}
Fk:loadTranslationTable{
    ["lingling__zhizi"] = "制字",
    [":lingling__zhizi"] = "当你使用或被其他角色使用一张锦囊牌后，若你没有【影】，你获得一张不计入手牌上限的【影】。",
    ["@@lingling__zhizi-inhand"] = "制字",
}

local U = require "packages/lingling/util"

--[[zhizi:addEffect("viewas",{
    pattern = ".|.|.|.|.|basic",
    prompt = "#zhendan",
    interaction = function(self, player)
        local all_names = Fk:getAllCardNames("b")
        local names = player:getViewAsCardNames(zhizi.name, all_names, nil, player:getTableMark("lingling__zhizi-turn"))
        if #names > 0 then
        return UI.CardNameBox { choices = names, all_choices = all_names }
        end
    end,
    handly_pile = true,
    card_filter = function(self, player, to_select, selected)
        return #selected == 0 and Fk:getCardById(to_select).suit == Card.Spade
    end,
    view_as = function(self, player, cards)
        if #cards ~= 1 or not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcards(cards)
        card.skillName = zhizi.name
        return card
    end,
    before_use = function(self, player, use)
        player.room:addTableMark(player, "lingling__zhizi-turn", use.card.trueName)
    end,
    enabled_at_play = function (self, player)
        return not player:isNude() and #player:getViewAsCardNames(zhizi.name, Fk:getAllCardNames("b"), nil, player:getTableMark("lingling__zhizi-turn")) > 0
    end,
    enabled_at_response = function (self, player, response)
        return not player:isNude() and #player:getViewAsCardNames(zhizi.name, Fk:getAllCardNames("b"), nil, player:getTableMark("lingling__zhizi-turn")) > 0
    end,
})]]--

zhizi:addEffect(fk.CardUseFinished,{
    can_trigger = function (self, event, target, player, data)
        return  player:hasSkill(zhizi.name) and data.card.type == Card.TypeTrick and not table.find(player:getCardIds("h"), function(id)
            return Fk:getCardById(id).trueName == "shade"
        end) and (player == target or (data.from ~= player and table.contains(data.tos, player)))
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local ids = U.getShade(room, 1)
        room:obtainCard(player, ids, true, fk.ReasonJustMove, player, zhizi.name, "@@lingling__zhizi-inhand")
    end,
})
zhizi:addEffect("maxcards", {
    exclude_from = function(self, player, card)
        return card:getMark("@@lingling__zhizi-inhand") ~= 0
    end,
})

return zhizi